﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RoutesManager.aspx.cs" Inherits="GPSTrackingWebsiteManager.Pages.RoutesManager" %>

<!DOCTYPE html>

<link href="../../Css/GPSTrackingWebsite.css" rel="stylesheet" />
<link href="../../Css/messi.css" rel="stylesheet" />
<script src="../../Javascript/jquery-1.11.1.min.js"></script>
<script src="../../Javascript/messi.js"></script>
<script src="../../Javascript/Custom.js"></script>
<script src="../../Javascript/WindowMessageManager.js"></script>
<script src="../../Javascript/ObjectsV2.js"></script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">

            //Windows Message Manager 
            var objWindowsMessageManager = new WindowsMessageManager();
           
            var opener = GetRadWindow();
            var RoutesManager = new RoutesManager();
            var Companies = new Companies();
            var lenghMsg = 450;

            function openRadWin() {
                opener.openRadWin();
            }

            function GetRadWindow() {
                var oWindow = null;
                if (window.radWindow)
                    oWindow = window.radWindow;
                else if (window.frameElement.radWindow)
                    oWindow = window.frameElement.radWindow;
                return oWindow.BrowserWindow;
            }

            function initializeObjects() {
                opener.objMapControl.initializeRoutesManagerObject();
            }

            function clearObjects()
            {
                if (opener.globalRoutesManager.gpsImeiSelected != -1)
                {
                    opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, false);
                }
                opener.objMapControl.hideClientsRoutes();
                hideShowAllClientsSelected(false);
            }

            function restorePage() {
                if (opener.globalRoutesManager.gpsImeiSelected != -1) {
                    opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, true);
                }
                opener.objMapControl.showClientsRoutes();
                hideShowAllClientsSelected(true);
            }

            function hideShowAllClientsSelected(visible) {
                for (iii = 0; iii < opener.globalRoutesManager.allClientsList.length; iii++) {
                    if (opener.globalRoutesManager.allClientsList[iii].checked) {
                        opener.objMapControl.setVisibleMarker(opener.globalRoutesManager.allClientsList[iii].marker, visible);
                    }
                }
            }



            function loadInfo() {
                initializeObjects();
                getCompaniesByAdmin();
            }

            function getCompaniesByAdmin() {
                requestStart(getrpvRoutesManagerPanelUpdateControl());
                PageMethods.wsGetCompaniesByAdminUsername(getCompaniesByAdminOk, getCompaniesByAdminError);
            }

            function getCompaniesByAdminOk(object) {
                Companies.openXMLCompaniesByAdminUsername(object, opener.globalRoutesManager.companiesList);
                Companies.loadCompaniesDataSource(getCompaniesGrid(), opener.globalRoutesManager.companiesList, opener.globalRoutesManager.companiesDataSource);
                if (opener.globalRoutesManager.companiesList.length == 1) {
                    getCompaniesGrid().selectItem(0);
                    //opener.globalRoutesManager.companyIDSelected = opener.globalRoutesManager.companiesList[0].companyID;
                    responseEnd(getrpvRoutesManagerPanelUpdateControl());
                    CompaniesGridSelected(opener.globalRoutesManager.companiesList[0].companyID);
                }
                else {
                    responseEnd(getrpvRoutesManagerPanelUpdateControl());
                }
            }

            function getCompaniesByAdminError(error) {
                responseEnd(getrpvRoutesManagerPanelUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.routesAdministrator);
            }

            function CompaniesGrid_OnRowClick(sender, args) {
                CompaniesGridSelected(args.getDataKeyValue("CompanyID"));
            }

            function CompaniesGridSelected(companyID) {
                var index = Companies.getIndexCompanyID(companyID);
                if (index != -1) {
                    opener.globalRoutesManager.companyIDSelected = companyID;
                    getDepartmentsByCompanyID();
                    getClientsByCompanyID();
                }
            }

            function getDepartmentsByCompanyID() {
                requestStart(getrpvRoutesManagerPanelUpdateControl());
                PageMethods.wsGetAllDepartmentsByCompanyIDAndAdminUsername(opener.globalRoutesManager.companyIDSelected, getDepartmentsByCompanyIDOk, getDepartmentsByCompanyIDError);
            }

            function getDepartmentsByCompanyIDOk(object) {

                clearList(opener.globalRoutesManager.usersGroupsList);
                clearDataSource(opener.globalRoutesManager.usersGroupsDataSource, getUsersGroupsGrid(), true);

                clearList(opener.globalRoutesManager.usersList);
                clearDataSource(opener.globalRoutesManager.usersDataSource, getUsersRoutesGrid(), true);

                clearList(opener.globalRoutesManager.gpsImeiList);
                clearDataSource(opener.globalRoutesManager.gpsImeiDataSource, getGpsRoutesGrid(), true);


                opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, null);
                opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, null);
                opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, false);



                RoutesManager.openXMLDepartmentsByCompanyID(object, opener.globalRoutesManager.departmentsList);
                RoutesManager.loadDepartmentsDataSource(getDeparmentsGrid(), opener.globalRoutesManager.departmentsDataSource, opener.globalRoutesManager.departmentsList);

                if (opener.globalRoutesManager.departmentsList.length == 1) {
                    getDeparmentsGrid().selectItem(0);
                    //opener.globalRoutesManager.companyIDSelected = opener.globalRoutesManager.companiesList[0].companyID;
                    responseEnd(getrpvRoutesManagerPanelUpdateControl());
                    DepartmentsGridSelected(opener.globalRoutesManager.departmentsList[0].departmentID);
                }
                else {
                    responseEnd(getrpvRoutesManagerPanelUpdateControl());
                }

                //responseEnd(getrpvRoutesManagerPanelUpdateControl());
            }

            function getDepartmentsByCompanyIDError(error) {
                responseEnd(getrpvRoutesManagerPanelUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.routesAdministrator);
            }

            function getClientsByCompanyID() {
                requestStart(getrpvRoutesManagerPanelUpdateControl());
                PageMethods.wsGetClientsByCompanyID(opener.globalRoutesManager.companyIDSelected, getClientsByCompanyIDOk, getClientsByCompanyIDError);
            }

            function getClientsByCompanyIDOk(object) {
                RoutesManager.clearClientsMarkers(opener);
                opener.globalRoutesManager.gpsImeiSelected = -1;
                RoutesManager.openXMLAllClientsByCompanyID(object, opener.globalRoutesManager.allClientsList, opener.objMapControl);
                //RoutesManager.loadAllClientsByCompanyIDDataSource(getClientsRoutesGrid(), opener.globalRoutesManager.allClientsList, opener.globalRoutesManager.allClientsDataSource, opener);
                RoutesManager.loadAllGroupClientsByCompanyIDDataSource(getClientGroupRoutesGrid(), opener.globalRoutesManager.allClientsList, opener.globalRoutesManager.allClientGroupsDataSource, opener);
                getClientGroupRoutesGrid().clearSelectedItems();
                refreshAllClients();
                responseEnd(getrpvRoutesManagerPanelUpdateControl());
            }

            function getClientsByCompanyIDError(error) {
                responseEnd(getrpvRoutesManagerPanelUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.routesAdministrator);
            }

            function DepartmentsGrid_OnRowClick(sender, args) {
                DepartmentsGridSelected(args.getDataKeyValue("DepartmentID"));
            }
            
            function DepartmentsGridSelected(departmentID) {
                var index = RoutesManager.getIndexDepartmentID(opener.globalRoutesManager.departmentsList, departmentID);
                if (index != -1) {
                    opener.globalRoutesManager.departmentIDSelected = departmentID;
                    getUsersGroupsByDepartmentID();
                }
            }

            function getUsersGroupsByDepartmentID() {
                requestStart(getrpvRoutesManagerPanelUpdateControl());
                PageMethods.wsGetAllUsersGroupsByDepartmentID(opener.globalRoutesManager.departmentIDSelected, getUsersGroupsByDepartmentIDOk, getUsersGroupsByDepartmentIDError);
            }

            function getUsersGroupsByDepartmentIDOk(object) {

                clearList(opener.globalRoutesManager.usersList);
                clearDataSource(opener.globalRoutesManager.usersDataSource, getUsersRoutesGrid(), true);

                clearList(opener.globalRoutesManager.gpsImeiList);
                clearDataSource(opener.globalRoutesManager.gpsImeiDataSource, getGpsRoutesGrid(), true);

                opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, null);
                opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, null);
                opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, false);

                RoutesManager.openXMLUsersGroupsByDepartmentID(object, opener.globalRoutesManager.usersGroupsList);
                RoutesManager.loadUsersGroupsDataSource(getUsersGroupsGrid(), opener.globalRoutesManager.usersGroupsDataSource, opener.globalRoutesManager.usersGroupsList);

                if (opener.globalRoutesManager.usersGroupsList.length == 1) {
                    getUsersGroupsGrid().selectItem(0);
                    //opener.globalRoutesManager.companyIDSelected = opener.globalRoutesManager.companiesList[0].companyID;
                    responseEnd(getrpvRoutesManagerPanelUpdateControl());
                    UsersGroupsGridSelected(opener.globalRoutesManager.usersGroupsList[0].userGroupID);
                }
                else {
                    responseEnd(getrpvRoutesManagerPanelUpdateControl());
                }

                //responseEnd(getrpvRoutesManagerPanelUpdateControl());
            }

            function getUsersGroupsByDepartmentIDError(error) {
                responseEnd(getrpvRoutesManagerPanelUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.routesAdministrator);
            }

            function UsersGroupsGrid_OnRowClick(sender, args) {
                UsersGroupsGridSelected(args.getDataKeyValue("UserGroupID"));
            }

            function UsersGroupsGridSelected(userGroupID) {
                var index = RoutesManager.getIndexUserGroupID(opener.globalRoutesManager.usersGroupsList, userGroupID);
                if (index != -1) {
                    opener.globalRoutesManager.userGroupIDSelected = userGroupID;
                    getAllUsersByUserGroupID();
                }
            }

            function getAllUsersByUserGroupID() {
                requestStart(getrpvRoutesManagerPanelUpdateControl());
                PageMethods.wsGetUsersByUserGroupID(opener.globalRoutesManager.userGroupIDSelected, getAllUsersByUserGroupIDOk, getAllUsersByUserGroupIDError);
            }

            function getAllUsersByUserGroupIDOk(object) {
                clearList(opener.globalRoutesManager.usersList);
                clearDataSource(opener.globalRoutesManager.usersDataSource, getUsersRoutesGrid(), true);

                clearList(opener.globalRoutesManager.gpsImeiList);
                clearDataSource(opener.globalRoutesManager.gpsImeiDataSource, getGpsRoutesGrid(), true);

                opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, null);
                opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, null);
                opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, false);

                RoutesManager.openXMLUsersByUserGroupID(object, opener.globalNotificationManager.usersList);
                RoutesManager.loadUsersRouteByUserGroupIDDataSource(getUsersRoutesGrid(), opener.globalNotificationManager.usersDataSource, opener.globalNotificationManager.usersList);

                if (opener.globalRoutesManager.usersList.length == 1) {
                    getUsersRoutesGrid().selectItem(0);
                    //opener.globalRoutesManager.companyIDSelected = opener.globalRoutesManager.companiesList[0].companyID;
                    responseEnd(getrpvRoutesManagerPanelUpdateControl());
                    UsersRouteGridSelected(opener.globalRoutesManager.usersList[0].username);
                }
                else {
                    responseEnd(getrpvRoutesManagerPanelUpdateControl());
                }
                //responseEnd(getrpvRoutesManagerPanelUpdateControl());
            }

            function getAllUsersByUserGroupIDError(error) {
                responseEnd(getrpvRoutesManagerPanelUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.routesAdministrator);
            }

            function UsersRoutesGrid_OnRowClick(sender, args) {

                UsersRouteGridSelected(args.getDataKeyValue("Username"));
            }

            function UsersRouteGridSelected(username) {
                

                //if (opener.globalRoutesManager.usernameSelected != username) {
                opener.globalRoutesManager.usernameSelected = username;
                getImeiByUser();
                //}
            }

            function getImeiByUser() {
                requestStart(getrpvRoutesManagerPanelUpdateControl());
                PageMethods.wsGetImeiByUser(opener.globalRoutesManager.companyIDSelected, opener.globalRoutesManager.usernameSelected, getImeiByUserOk, getImeiByUserError);
            }

            function getImeiByUserOk(object) {
                clearList(opener.globalRoutesManager.gpsImeiList);
                clearDataSource(opener.globalRoutesManager.gpsImeiDataSource, getGpsRoutesGrid(), true);

                opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, null);
                opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, null);
                opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, false);

                RoutesManager.openXMLImeiByUser(object, opener.globalRoutesManager.gpsImeiList);
                RoutesManager.loadImeiDataSource(getGpsRoutesGrid(), opener.globalRoutesManager.gpsImeiDataSource, opener.globalRoutesManager.gpsImeiList);

                responseEnd(getrpvRoutesManagerPanelUpdateControl());
            }

            function getImeiByUserError(error) {
                responseEnd(getrpvRoutesManagerPanelUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.routesAdministrator);
            }

            function GpsRoutesGrid_OnRowClick(sender, args) {
                var imei = args.getDataKeyValue("GPSImei");
                var index = -1;

                if (opener.globalRoutesManager.gpsImeiSelected != imei) {
                    opener.globalRoutesManager.gpsImeiSelected = imei;

                    index = getIndexGpsImei(opener.globalRoutesManager.gpsImeiList, imei);
                    if (index != -1) {
                        opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, opener.globalRoutesManager.gpsImeiList[index].position);
                        opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, opener.globalRoutesManager.gpsImeiList[index].image);
                        opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, true);
                        opener.objMapControl.setTitleMarker(opener.objMapControl.originImeiMarker, opener.globalRoutesManager.gpsImeiList[index].name);
                        opener.objMapControl.setCenterMap(opener.globalRoutesManager.gpsImeiList[index].position);
                    }
                    else {
                        opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, null);
                        opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, null);
                        opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, false);
                    }

                    getGpsRoutesGrid().clearSelectedItems();
                    /*for (i = 0; i < opener.globalRoutesManager.allClientsList.length; i++) {
                        opener.globalRoutesManager.allClientsList[i].checked = false;
                    }*/
                    RoutesManager.loadAllClientsByCompanyIDDataSource(getClientsRoutesGrid(), opener.globalRoutesManager.allClientsList, opener.globalRoutesManager.allClientsDataSource, opener);//loadCustomersGroupsRoutesDataSource();
                }
                else {
                    index = getIndexGpsImei(opener.globalRoutesManager.gpsImeiList, opener.globalRoutesManager.gpsImeiSelected);

                    if (index != -1) {
                        opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, opener.globalRoutesManager.gpsImeiList[index].position);
                        opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, opener.globalRoutesManager.gpsImeiList[index].image);
                        opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, true);
                        opener.objMapControl.setTitleMarker(opener.objMapControl.originImeiMarker, opener.globalRoutesManager.gpsImeiList[index].name);
                        opener.objMapControl.setCenterMap(opener.globalRoutesManager.gpsImeiList[index].position);
                    }
                    else {
                        opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, null);
                        opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, null);
                        opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, false);
                    }
                }
            }

            function ClientGroupsRoutesGrid_RowSelecting(sender, args) {
                requestStart(getrpvRoutesManagerPanelUpdateControl());
                RoutesManager.clientGroupsRoutesGridRowSelection(opener.globalRoutesManager.allClientsList, args.getDataKeyValue("ClientGroupID"));
                refreshAllClients();
                responseEnd(getrpvRoutesManagerPanelUpdateControl());
            }

            function ClientGroupsRoutesGrid_RowDeselecting(sender, args) {
                requestStart(getrpvRoutesManagerPanelUpdateControl());
                RoutesManager.clientGroupsRoutesGridRowDeselecting(opener.globalRoutesManager.allClientsList, args.getDataKeyValue("ClientGroupID"));
                refreshAllClients();
                responseEnd(getrpvRoutesManagerPanelUpdateControl());
            }

            function ClientsRoutesGrid_RowSelecting(sender, args) {
                RoutesManager.clientsRoutesGridRowSelection(args, opener);
            }

            function ClientsRoutesGrid_RowDeselecting(sender, args) {
                RoutesManager.clientsRoutesGridRowDeselecting(args, opener);
            }

            function ClientsRoutesSelectedGrid_OnRowClick(sender, args) {
                var index = -1;
                if (args._domEvent.target.cellIndex == 0) {// La columna 0 Representa la columna de eliminar
                    index = RoutesManager.getIndexClientID(opener.globalRoutesManager.allClientsList, args.getDataKeyValue("ClientID"));
                    if (index != -1) {
                        if (confirm('¿Desea quitar el Cliente para la ruta?')) {
                            opener.globalRoutesManager.allClientsList[index].checked = false;
                            refreshAllClients();
                        }
                    }
                }
                else {
                    index = RoutesManager.getIndexClientID(opener.globalRoutesManager.allClientsList, args.getDataKeyValue("ClientID"));
                    if (index != -1) {
                        opener.objMapControl.setCenterMap(opener.globalRoutesManager.allClientsList[index].position);
                    }
                }
            }

            function refreshAllClients() {
                RoutesManager.clearNumPosClients(opener);
                RoutesManager.clearKmsAndDurationClients(opener, true);
                opener.globalRoutes.isClear = true;
                RoutesManager.loadAllClientsByCompanyIDDataSource(getClientsRoutesGrid(), opener.globalRoutesManager.allClientsList, opener.globalRoutesManager.allClientsDataSource, opener);
                getClientsRoutesGrid().clearSelectedItems();
                RoutesManager.loadAllClientsSelectedDataSource(getClientsRoutesSelectedGrid(), opener.globalRoutesManager.allClientsList, opener.globalRoutesManager.allClientsDataSource, opener);
                getClientsRoutesSelectedGrid().clearSelectedItems();
                opener.globalRoutes.isClear = false;
            }

            function generateRoutes() {
                opener.globalRoutes.cantErrors = 0;
                requestStart(getrpvRoutesManagerPanelUpdateControl());

                opener.globalRoutes.totallyClients = RoutesManager.getCantClientSelected(opener);
                if (opener.globalRoutesManager.gpsImeiSelected != -1) {
                    if (opener.globalRoutes.totallyClients > 1) {
                        opener.globalRoutes.clientsRoutesSelectedTableView = getClientsRoutesSelectedGrid();

                        refreshAllClients();
                        opener.objMapControl.clientsRoutes = [];
                        opener.globalRoutes.firstClientRoute = true;

                        clearDataSource(opener.globalRoutesManager.allClientsSelectedDataSource, getClientsRoutesSelectedGrid(), true);
                        opener.globalRoutes.numPos = 0;
                        RoutesManager.clearNumPosClients(opener);

                        opener.globalRoutes.updatePanelObject = getrpvRoutesManagerPanelUpdateControl();
                        opener.globalRoutes.responseEndObject = getResponseEnd();
                        opener.globalRoutes.btnGenerateRoute = btnGenerateRoute();
                        opener.globalRoutes.btnGenerateRoute.value = "Cliente 1 de " + opener.globalRoutes.totallyClients;
                        opener.objMapControl.calculateSmartRoute(null);

                    }
                    else {
                        objWindowsMessageManager.show_Warning("Debe seleccionar almenos dos clientes para generar la ruta", titles.routesAdministrator, lenghMsg);
                        responseEnd(getrpvRoutesManagerPanelUpdateControl());
                    }
                }
                else {
                    objWindowsMessageManager.show_Warning("Debe seleccionar un dispositivo para iniciar el cálculo de Ruta", titles.routesAdministrator, lenghMsg);
                    responseEnd(getrpvRoutesManagerPanelUpdateControl());
                }
            }


            function saveRoutes() {

                var dateSelectedList = [];

                var timeBeginSelected;
                var timeEndSelected;

                var date;
                var year;
                var month;
                var day;
                var hoursBegin;
                var minutesBegin;
                var hoursEnd;
                var minutesEnd;

                var dates = [];
                dates = getBeginDateSelected().get_selectedDates();

                if (dates.length > 0) {

                    if (getBeginTimeSelected().get_selectedDate() != null) {

                        hoursBegin = getBeginTimeSelected().get_selectedDate().getHours();
                        minutesBegin = getBeginTimeSelected().get_selectedDate().getMinutes();
                        timeBeginSelected = leftpad(hoursBegin, 2) + ':' + leftpad(minutesBegin, 2) + ':00';

                        if (getEndTimeSelected().get_selectedDate() != null) {

                            hoursEnd = getEndTimeSelected().get_selectedDate().getHours();
                            minutesEnd = getEndTimeSelected().get_selectedDate().getMinutes();
                            timeEndSelected = leftpad(hoursEnd, 2) + ':' + leftpad(minutesEnd, 2) + ':00';

                            for (i = 0; i < dates.length; i++) {
                                date = dates[i];
                                year = date[0];
                                month = date[1];
                                day = date[2];

                                dateSelectedList.push(leftpad(year, 4) + '/' + leftpad(month, 2) + '/' + leftpad(day, 2));

                            }

                            var clientsList = [];
                            var numPosList = [];
                            var distanceList = [];
                            var durationList = [];

                            for (numPos = 1; numPos <= opener.globalRoutesManager.allClientsList.length; numPos++) {

                                for (i = 0; i < opener.globalRoutesManager.allClientsList.length; i++) {
                                    if (opener.globalRoutesManager.allClientsList[i].checked && opener.globalRoutesManager.allClientsList[i].numPos != null && opener.globalRoutesManager.allClientsList[i].numPos == numPos) {
                                        clientsList.push(opener.globalRoutesManager.allClientsList[i].clientID.toString());
                                        numPosList.push(opener.globalRoutesManager.allClientsList[i].numPos.toString());
                                        distanceList.push(opener.globalRoutesManager.allClientsList[i].kms.toString());
                                        //distanceList.push(opener.globalRoutesManager.allClientsList[i].kmsText);
                                        durationList.push(opener.globalRoutesManager.allClientsList[i].duration.toString());
                                        //durationList.push(opener.globalRoutesManager.allClientsList[i].durationText);
                                    }
                                }
                            }


                            if (clientsList.length > 1) {
                                requestStart(getrpvRoutesManagerPanelUpdateControl());
                                var clientGroupID = -1;
                                var latitudeOrigin = opener.objMapControl.originImeiMarker.position.lat();
                                var longitudeOrigin = opener.objMapControl.originImeiMarker.position.lng();
                                //PageMethods.wsClientsToVisitInsert(opener.globalRoutesManager.companyIDSelected, opener.globalRoutesManager.usernameSelected, opener.globalRoutesManager.gpsImeiSelected, dateSelectedList, clientsList, numPosList, distanceList, durationList, saveRoutesOk, saveRoutesError);
                                PageMethods.wsClientsToVisitInsert(opener.globalRoutesManager.companyIDSelected, opener.globalRoutesManager.usernameSelected, opener.globalRoutesManager.gpsImeiSelected, dateSelectedList, timeBeginSelected, timeEndSelected, clientGroupID, clientsList, numPosList, distanceList, durationList, latitudeOrigin, longitudeOrigin, saveRoutesOk, saveRoutesError);
                            }
                            else {
                                objWindowsMessageManager.show_Warning("No hay clientes para visita para guardar.", titles.routesAdministrator, lenghMsg);
                            }
                        }
                        else {
                            objWindowsMessageManager.show_Warning("Se debe seleccionar la hora final.", titles.routesAdministrator, lenghMsg);
                        }
                    }
                    else {
                        objWindowsMessageManager.show_Warning("Se debe seleccionar la hora de inicio.", titles.routesAdministrator, lenghMsg);
                    }
                }
                else {
                    objWindowsMessageManager.show_Warning("Se debe seleccionar una fecha.", titles.routesAdministrator, lenghMsg);
                }
            }

            function saveRoutesOk(object) {
                objWindowsMessageManager.show_Info("Se registraron los clientes de forma satisfactoria.", titles.routesAdministrator, lenghMsg);
                responseEnd(getrpvRoutesManagerPanelUpdateControl());
            }

            function saveRoutesError(error) {
                responseEnd(getrpvRoutesManagerPanelUpdateControl());
                objWindowsMessageManager.show_Error(error.get_message(), titles.routesAdministrator);
            }

            function getUsersRoutesGrid() {
                return $find("<%= rgUsersRoutesGrid.ClientID %>").get_masterTableView();
        }

        function btnGenerateRoute() {
            return $get('btnGenerateRoute');
        }

        function getCompaniesGrid() {
            return $find("<%= rgCompaniesGrid.ClientID %>").get_masterTableView();
        }

        function getDeparmentsGrid() {
            return $find("<%= rgDepartmentsGrid.ClientID %>").get_masterTableView();
        }

        function getClientsRoutesGrid() {
            return $find("<%= rgClientsRoutesGrid.ClientID %>").get_masterTableView();
        }

        function getClientGroupRoutesGrid() {
            return $find("<%= rgClientGroupRoutesGrid.ClientID %>").get_masterTableView();
        }

        function getClientsRoutesSelectedGrid() {
            return $find("<%= rgClientsRoutesSelectedGrid.ClientID %>").get_masterTableView();
        }

        function getUsersGroupsGrid() {
            return $find("<%= rgUsersGroupsGrid.ClientID %>").get_masterTableView();
        }

        function getGpsRoutesGrid() {
            return $find("<%= rgGpsRoutesGrid.ClientID %>").get_masterTableView();
        }

        function getrpvRoutesManagerPanelUpdateControl() {
            return "<%= rpvRoutesManager.ClientID %>";
        }

        function getBeginDateSelected() {
            return $find("<%= DateSelected.ClientID %>");
        }

        function getBeginTimeSelected() {
            return $find("<%= TimeBegin.ClientID %>");
        }

        function getEndTimeSelected() {
            return $find("<%= TimeEnd.ClientID %>");
        }

        function requestStart(object) {
            try {
                $find("<%= RadAjaxLoadingPanel1.ClientID%>").show(object);
            }
            catch (e) {
                null;
            }
        }

        function getResponseEnd() {
            try {
                return $find("<%= RadAjaxLoadingPanel1.ClientID%>");
            }
            catch (e) {
                null;
            }
        }

        function responseEnd(object) {
            try {
                $find("<%= RadAjaxLoadingPanel1.ClientID%>").hide(object);
            }
            catch (e) {
                null;
            }
        }




        </script>
    </telerik:RadScriptBlock>
</head>
<body onload="loadInfo()">
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true"></telerik:RadScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="AjaxControlID1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="Loading" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>


        <telerik:RadTabStrip ID="rtsRoutesManager" runat="server" SelectedIndex="0" MultiPageID="rmpRoutesManager"></telerik:RadTabStrip>
        <telerik:RadMultiPage ID="rmpRoutesManager" runat="server" SelectedIndex="0">
            <telerik:RadPageView ID="rpvRoutesManager" runat="server">
                <table style="text-align: left">
                    <tr>
                        <td>
                            <fieldset>
                                <legend>Compañias</legend>
                                <telerik:RadGrid ID="rgCompaniesGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="450px" OnNeedDataSource="rgCompaniesGrid_NeedDataSource" >
                                    <ClientSettings>
                                        <Selecting AllowRowSelect="True" />
                                        <ClientEvents OnRowClick="CompaniesGrid_OnRowClick" />
                                        <Scrolling AllowScroll="true" UseStaticHeaders="true" />
                                    </ClientSettings>
                                    <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="CompanyID" NoMasterRecordsText="No hay Compañias registradas">
                                        <CommandItemSettings ExportToPdfText="Export to PDF" />
                                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                        </RowIndicatorColumn>
                                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                        </ExpandCollapseColumn>
                                        <Columns>
                                            <telerik:GridBoundColumn DataField="CompanyID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="CompanyID" Visible="false">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" HeaderStyle-Width="100px"  ItemStyle-Width="100px">
                                            </telerik:GridBoundColumn>
                                        </Columns>
                                        <EditFormSettings>
                                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                            </EditColumn>
                                        </EditFormSettings>
                                    </MasterTableView>
                                    <FilterMenu EnableImageSprites="true">
                                    </FilterMenu>
                                </telerik:RadGrid>
                            </fieldset>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <fieldset>
                                <legend>Departamentos</legend>
                                <telerik:RadGrid ID="rgDepartmentsGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="450px" OnNeedDataSource="rgDepartmentsGrid_NeedDataSource">
                                    <ClientSettings>
                                        <Selecting AllowRowSelect="True" />
                                        <ClientEvents OnRowClick="DepartmentsGrid_OnRowClick" />
                                        <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                    </ClientSettings>
                                    <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="DepartmentID" NoMasterRecordsText="No hay Departamentos registrados">
                                        <CommandItemSettings ExportToPdfText="Export to PDF" />
                                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                        </RowIndicatorColumn>
                                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                        </ExpandCollapseColumn>
                                        <Columns>
                                            <telerik:GridBoundColumn DataField="DepartmentID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="DepartmentID" Visible="false">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true">
                                            </telerik:GridBoundColumn>
                                        </Columns>
                                        <EditFormSettings>
                                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                            </EditColumn>
                                        </EditFormSettings>
                                    </MasterTableView>
                                    <FilterMenu EnableImageSprites="true">
                                    </FilterMenu>
                                </telerik:RadGrid>
                            </fieldset>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <fieldset>
                                <legend>Grupo de Usuarios</legend>
                                <telerik:RadGrid ID="rgUsersGroupsGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="450px" OnNeedDataSource="rgUsersGroupsGrid_NeedDataSource">
                                    <ClientSettings>
                                        <Selecting AllowRowSelect="True" />
                                        <ClientEvents OnRowClick="UsersGroupsGrid_OnRowClick" />
                                        <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                    </ClientSettings>
                                    <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="UserGroupID" NoMasterRecordsText="No hay Grupos registrados">
                                        <CommandItemSettings ExportToPdfText="Export to PDF" />
                                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                        </RowIndicatorColumn>
                                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                        </ExpandCollapseColumn>
                                        <Columns>
                                            <telerik:GridBoundColumn DataField="UserGroupID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="UserGroupID" Visible="false">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true">
                                            </telerik:GridBoundColumn>
                                        </Columns>
                                        <EditFormSettings>
                                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                            </EditColumn>
                                        </EditFormSettings>
                                    </MasterTableView>
                                    <FilterMenu EnableImageSprites="true">
                                    </FilterMenu>
                                </telerik:RadGrid>
                            </fieldset>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <fieldset>
                                <legend>Usuarios</legend>
                                <telerik:RadGrid ID="rgUsersRoutesGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="450px" OnNeedDataSource="rgUsersRoutesGrid_NeedDataSource">
                                    <ClientSettings>
                                        <Selecting AllowRowSelect="True" />
                                        <ClientEvents OnRowClick="UsersRoutesGrid_OnRowClick" />
                                        <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                    </ClientSettings>
                                    <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="Username" NoMasterRecordsText="No hay usuarios registrados">
                                        <CommandItemSettings ExportToPdfText="Export to PDF" />
                                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                        </RowIndicatorColumn>
                                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                        </ExpandCollapseColumn>
                                        <Columns>
                                            <telerik:GridBoundColumn DataField="Username" FilterControlAltText="Filter Description column" HeaderText="Username" UniqueName="Username" Display="false">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" HeaderStyle-Width="150px" ItemStyle-Width="150px">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="FirstName" FilterControlAltText="Filter Description column" HeaderText="Apellido1" HeaderStyle-Width="150px" ItemStyle-Width="150px">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="LastName" FilterControlAltText="Filter Description column" HeaderText="Apellido2" HeaderStyle-Width="150px" ItemStyle-Width="150px">
                                            </telerik:GridBoundColumn>
                                        </Columns>
                                        <EditFormSettings>
                                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                            </EditColumn>
                                        </EditFormSettings>
                                    </MasterTableView>
                                    <FilterMenu EnableImageSprites="true">
                                    </FilterMenu>
                                </telerik:RadGrid>
                            </fieldset>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <fieldset>
                                <legend>Dispositivos registrados</legend>
                                <telerik:RadGrid ID="rgGpsRoutesGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="450px" OnNeedDataSource="rgGpsRoutesGrid_NeedDataSource">
                                    <ClientSettings>
                                        <Selecting AllowRowSelect="True" />
                                        <ClientEvents OnRowClick="GpsRoutesGrid_OnRowClick" />
                                        <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                    </ClientSettings>
                                    <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="GPSImei" NoMasterRecordsText="No hay gps registrados">
                                        <CommandItemSettings ExportToPdfText="Export to PDF" />
                                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                        </RowIndicatorColumn>
                                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                        </ExpandCollapseColumn>
                                        <Columns>
                                            <telerik:GridBoundColumn DataField="GPSImei" FilterControlAltText="Filter Description column" HeaderText="GPSImei" UniqueName="GPSImei" Visible="false">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true">
                                            </telerik:GridBoundColumn>
                                        </Columns>
                                        <EditFormSettings>
                                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                            </EditColumn>
                                        </EditFormSettings>
                                    </MasterTableView>
                                    <FilterMenu EnableImageSprites="true">
                                    </FilterMenu>
                                </telerik:RadGrid>
                            </fieldset>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <fieldset>
                                <legend>Grupo Clientes Registrados</legend>
                                <telerik:RadGrid ID="rgClientGroupRoutesGrid" runat="server" AllowMultiRowSelection="true" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="450px" OnNeedDataSource="rgClientGroupRoutesGrid_NeedDataSource">
                                    <ClientSettings>
                                        <Selecting AllowRowSelect="True" />
                                        <ClientEvents OnRowClick="" OnRowSelecting="ClientGroupsRoutesGrid_RowSelecting" OnRowDeselecting="ClientGroupsRoutesGrid_RowDeselecting" />
                                        <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                    </ClientSettings>
                                    <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="ClientGroupID" NoMasterRecordsText="No hay grupo de clientes registrados">
                                        <CommandItemSettings ExportToPdfText="Export to PDF" />
                                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                        </RowIndicatorColumn>
                                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                        </ExpandCollapseColumn>
                                        <Columns>
                                            <telerik:GridBoundColumn DataField="ClientGroupID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="ClientGroupID" Display="false">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="ClientGroupName" FilterControlAltText="Filter Description column" HeaderText="Grupo" HeaderStyle-Width="200px" ItemStyle-Width="200px">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridClientSelectColumn HeaderText="Seleccionar" UniqueName="chkSelectCustomer" HeaderStyle-Width="30px" ItemStyle-Width="30px">
                                            </telerik:GridClientSelectColumn>
                                        </Columns>
                                        <EditFormSettings>
                                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                            </EditColumn>
                                        </EditFormSettings>
                                    </MasterTableView>
                                    <FilterMenu EnableImageSprites="true">
                                    </FilterMenu>
                                </telerik:RadGrid>
                            </fieldset>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <fieldset>
                                <legend>Clientes Registrados</legend>
                                <telerik:RadGrid ID="rgClientsRoutesGrid" runat="server" AllowMultiRowSelection="true" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="450px" OnNeedDataSource="rgClientsRoutesGrid_NeedDataSource">
                                    <ClientSettings>
                                        <Selecting AllowRowSelect="True" />
                                        <ClientEvents OnRowClick="" OnRowSelecting="ClientsRoutesGrid_RowSelecting" OnRowDeselecting="ClientsRoutesGrid_RowDeselecting" />
                                        <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                    </ClientSettings>
                                    <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="ClientID" NoMasterRecordsText="No hay clientes registrados">
                                        <CommandItemSettings ExportToPdfText="Export to PDF" />
                                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                        </RowIndicatorColumn>
                                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                        </ExpandCollapseColumn>
                                        <Columns>
                                            <telerik:GridBoundColumn DataField="ClientID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="ClientID" Display="false">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="ClientName" FilterControlAltText="Filter Description column" HeaderText="Cliente" HeaderStyle-Width="200px" ItemStyle-Width="200px">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="ClientGroupName" FilterControlAltText="Filter Description column" HeaderText="Grupo" HeaderStyle-Width="200px" ItemStyle-Width="200px">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridClientSelectColumn HeaderText="Seleccionar" UniqueName="chkSelectCustomer">
                                            </telerik:GridClientSelectColumn>
                                        </Columns>
                                        <EditFormSettings>
                                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                            </EditColumn>
                                        </EditFormSettings>
                                    </MasterTableView>
                                    <FilterMenu EnableImageSprites="true">
                                    </FilterMenu>
                                </telerik:RadGrid>
                            </fieldset>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <fieldset>
                                <legend>Clientes Asociados</legend>
                                <telerik:RadGrid ID="rgClientsRoutesSelectedGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" Width="450px" OnNeedDataSource="rgClientsRoutesSelectedGrid_NeedDataSource">
                                    <ClientSettings>
                                        <Selecting AllowRowSelect="True" />
                                        <ClientEvents OnRowClick="ClientsRoutesSelectedGrid_OnRowClick" OnRowDeselecting="" OnRowSelecting="" />
                                        <Scrolling AllowScroll="True" UseStaticHeaders="true" />
                                    </ClientSettings>
                                    <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" ClientDataKeyNames="ClientID" NoMasterRecordsText="No hay clientes registrados">
                                        <CommandItemSettings ExportToPdfText="Export to PDF" />
                                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                        </RowIndicatorColumn>
                                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                        </ExpandCollapseColumn>
                                        <Columns>
                                            <telerik:GridImageColumn ImageUrl="..\..\Template\Icons\16px\Delete.gif" UniqueName="DeleteColumn" HeaderStyle-Width="35px" ItemStyle-Width="35px">
                                            </telerik:GridImageColumn>
                                            <telerik:GridBoundColumn DataField="ClientID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="ClientID" Display="false">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="NumPos" FilterControlAltText="Filter Description column" HeaderText="Orden" HeaderStyle-Width="50px" ItemStyle-Width="50px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="ClientName" FilterControlAltText="Filter Description column" HeaderText="Cliente" HeaderStyle-Width="100px" ItemStyle-Width="100px">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="ClientGroupName" FilterControlAltText="Filter Description column" HeaderText="Grupo" HeaderStyle-Width="100px" ItemStyle-Width="100px">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="KmsText" FilterControlAltText="Filter Description column" HeaderText="Distancia" HeaderStyle-Width="70px" ItemStyle-Width="70px">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="DurationText" FilterControlAltText="Filter Description column" HeaderText="Duración">
                                            </telerik:GridBoundColumn>
                                        </Columns>
                                        <EditFormSettings>
                                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                            </EditColumn>
                                        </EditFormSettings>
                                    </MasterTableView>
                                    <FilterMenu EnableImageSprites="true">
                                    </FilterMenu>
                                </telerik:RadGrid>
                            </fieldset>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <fieldset>
                                <legend>Asociación de Clientes</legend>
                                <table>
                                    <tr>
                                        <td>
                                            <input id="btnClients" type="button" value="Asociar Cliente" onclick="refreshAllClients();" />
                                        </td>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                        <td>
                                            <input id="btnGenerateRoute" type="button" value="Generar Rutas" onclick="generateRoutes();" />
                                        </td>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                        <td>
                                            
                                        </td>
                                    </tr>
                                </table>
                            </fieldset>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <fieldset>
                                <legend>Guardar Orden de Clientes de Visita</legend>
                                <table>
                                    <tr>
                                        <td>
                                            <telerik:RadCalendar ID="DateSelected" runat="server" CultureInfo="es-CR" EnableMultiSelect="true">
                                            </telerik:RadCalendar>
                                        </td>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                        <td>
                                            <table>
                                                <tr>
                                                    <td>Hora Desde </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <telerik:RadTimePicker ID="TimeBegin" runat="server" Width="100px">
                                                        </telerik:RadTimePicker>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Hora Hasta </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                         <telerik:RadTimePicker ID="TimeEnd" runat="server" Width="100px">
                                                        </telerik:RadTimePicker>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <input id="btnSaveRoutes" type="button" value="Guardar Rutas" onclick="saveRoutes();" />
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                        
                                    </tr>
                                </table>
                            </fieldset>
                        </td>
                    </tr>                   
                </table>
            </telerik:RadPageView>
        </telerik:RadMultiPage>

        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default"></telerik:RadAjaxLoadingPanel>     
                              
           
    </form>
</body>
</html>
